﻿CREATE PROCEDURE [dbo].[StoreAnalogSensor]
	@SensorId bigint,
  @SensorType int,
	@Created datetimeoffset,	
  @RawValue tinyint,
  @RealValue decimal(11, 4)
AS
  begin transaction

  if not exists (select Id from Sensor where Id = @SensorId)
    begin
      insert Sensor (Id, Name) values (@SensorId, 'Unnamed')
    end 

  insert AnalogSensor (SensorId, SensorType, Created, RawValue, RealValue)
  values (@SensorId, @SensorType, @Created, @RawValue, @RealValue)
	
  commit

